import request from '@/utils/request';
import config from "@/config";

// 接口地址
const url = {
    TaskContentAddUrl: `${config.domain}/bus/task-content/addTaskContent`,
    TaskContentUpdateUrl: `${config.domain}/bus/task-content/updateTaskContent`,
    TaskContentGetDetail: `${config.domain}/bus/task-content/getDetail`,
    TaskContentListUrl: `${config.domain}/bus/task-content/list`,
    TaskCommitListUrl: `${config.domain}/bus/task-commit-record/commitInfoList`
};

/**
 * 添加话题
 * @param params
 * @returns {Promise<void>}
 */
export async function addTaskContent(params) {
    return request(url.TaskContentAddUrl, {
        method: "POST",
        body: params
    });
}

/**
 * 更新话题
 * @param params
 * @returns {Promise<void>}
 */
export async function updateTaskContent(params) {
    return request(url.TaskContentUpdateUrl, {
        method: "POST",
        body: params
    });
}


/**
 * 获取话题详情，包括题目列表
 * @param id
 * @returns {Promise<void>}
 */
export async function getTaskDetails(id) {
    return request(url.TaskContentGetDetail + `/${id}`);
}

/**
 * 获取话题列表
 * @param params
 * @returns {Promise<void>}
 */
export async function taskList(params) {
    const { pageSize, currentPage, ...searchData } = params || {};
    let reqBody = {
        size:pageSize || 10,
        current: currentPage || 0,
        search: searchData || {},
        ascs: [],
        descs: []
    };
    console.log(reqBody);
    return request(url.TaskContentListUrl, {
        method: "POST",
        body: reqBody
    });
}

/**
 * 获取话题提交内容列表列表
 * 页大小此处写死10
 * @param params
 * @returns {Promise<void>}
 */
export async function taskCommitList(params) {
    console.log(params)
    const { current, ...searchData } = params || {};
    let reqBody = {
        size: 3,
        current: current || 0,
        search: searchData || {},
    };
    return request(url.TaskCommitListUrl, {
        method: "POST",
        body: reqBody
    });
}

